package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.smartgwt.client.util.SC;

import de.openkanban.client.ui.board.KanbanView;
import de.openkanban.shared.dto.KanbanDto;

/**
 * Callback that handles update kanban request
 */
public class UpdateKanbanRequestCallback implements RequestCallback {

	private KanbanView kanbanView;

	public UpdateKanbanRequestCallback(KanbanView kanbanView) {
		super();
		this.kanbanView = kanbanView;
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		KanbanDto kanbanDto = new KanbanDto(response.getText());
		if (response.getStatusCode() < 300 && kanbanDto.isCallSuccessfull()) {
			kanbanView.setKanbanDto(kanbanDto);
		} else {
			SC.say("Fehler: " + response.getStatusText());
		}
	}

	@Override
	public void onError(Request request, Throwable exception) {

	}

}
